package club.baimahu.pencil.domain.session;

import com.google.common.util.concurrent.AtomicDouble;
import club.baimahu.pencil.domain.entity.Goods;
import lombok.Data;
import org.springframework.util.Assert;

/**
 * 商品库存
 */
@Data
public class GoodsStock {

    private Goods goods;

    private AtomicDouble amount;
    //最小库存，当前库存量小于minAmount时，需要采购
    private double minAmount = 1;
    //需要采购的数量
    private double buyAmount = 1;

    private  GoodsStock(){

    }

    public GoodsStock(Goods goods,   double amount){
        this.goods = goods;
        this.amount = new AtomicDouble(amount);
    }

    public void reduceAmount(double reduceAmount){
        Assert.isTrue(reduceAmount>0,"addAmount is illegal");
        amount.addAndGet(-reduceAmount);
    }

    public void addAmount(double addAmount){
        Assert.isTrue(addAmount>0,"addAmount is illegal");
        amount.addAndGet(addAmount);
    }

    public double getAmount(){
        return amount.doubleValue();
    }

    public AtomicDouble getAtomicAmount(){
        return amount;
    }



}
